﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace Settings_Configurator
{
    public partial class Connection : Form
    {
        public Connection()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.textBox5.Text == "")
            {
                MessageBox.Show("Choose your Config Database");
            }
            else
            {
                try
                {
                    string conn_str = "server=" + this.textBox1.Text + ";port=" + this.textBox2.Text +
                        ";uid=" + this.textBox3.Text + ";pwd=" + this.textBox4.Text + ";database="+this.textBox5.Text+";";

                    MySqlConnection conn = new MySqlConnection(conn_str);
                    conn.Open();
                }
                catch (MySqlException ex)
                {
                    switch (ex.Number)
                    {
                        case 0:
                            MessageBox.Show("Cannot connect to server.");
                            break;
                        case 1045:
                            MessageBox.Show("Invalid username/password, please try again");
                            break;
                    }
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.textBox1.Clear();
            this.textBox2.Clear();
            this.textBox3.Clear();
            this.textBox4.Clear();
            this.textBox5.Clear();
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AboutBox1 settings = new AboutBox1();
            settings.ShowDialog();
        }

        private void einstellungenSettingsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Settings settings = new Settings();
            settings.ShowDialog();
        }

        private void settingsToolStripMenuItem_Click(object sender, EventArgs e){}

        private void endeExitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }    }
}
